package {
	import com.bumpslide.events.DragEvent;
	import com.bumpslide.tween.FTween;
	import com.bumpslide.ui.Applet;
	import com.bumpslide.ui.Box;
	import com.bumpslide.ui.FramerateMonitor;
	import com.bumpslide.ui.behavior.DragBehavior;
	
	import flash.geom.Point;
	import flash.geom.Rectangle;	

	/**
	 * Drag Behavior Test 
	 * 
	 * @mxmlc -sp=../../classes -default-background-color 0xeeeeee -default-frame-rate 60
	 * @author David Knape
	 */
	public class DraggingTest extends Applet {

		private var box1:Box;
		private var box2:Box;
		private var previousLoc:Point;

		override protected function addChildren():void {
					
			super.addChildren();	
			
			// make some boxes... 
			box1 = addChild( new Box(0x000088, 40, 40, 10, 10, 3) ) as Box;					
			box2 = addChild( new Box(0x880000, 40, 40, 60, 10, 3) ) as Box;
			
			// enable drag behavior on box2 with a bounding rectangle
			DragBehavior.init(box1, new Rectangle(10, 10, 400, 300));
			
			// enable drag behavior on box2, but don't let DragBehavior Drag it
			DragBehavior.init(box2, null, false);
			
			// create our own custom drag motion by tapping in to the events that the
			// drag behavior dispatches from the dragTarget 
			box2.addEventListener(DragEvent.EVENT_DRAG_MOVE, customDrag);
			
			addChild( new FramerateMonitor() );
		}

		// position the box using FTween
		private function customDrag(event:DragEvent):void {
			FTween.ease( box2, 'x', event.start.x + event.delta.x, .2);
			FTween.ease( box2, 'y', event.start.y + event.delta.y, .2);
		}
	}
}
